<html>
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
</head>
<body>
<form action="">
    验证码:
    <input type="text" name="captchaCode">
    <input type="hidden" name="captchaId">
    <img src="" alt="" id="captcha">
    <br>
    <input type="submit" value="提交">
</form>

<script src="https://cdn.bootcss.com/jquery/2.2.3/jquery.min.js"></script>
<script>
    var verifyId = new Date().getTime() + parseInt(Math.random() * 100000),
        url = "/v1/";

    $("input[name=captchaId]").val(verifyId);

    setVerify();

    $("#verify").click(setVerify);

    function setVerify() {
        $.post(url + "createCaptcha", {captchaId: verifyId}, function (data) {
            $("#captcha").attr("src", data.data);
        }, "json");
    }

    $("form").submit(function () {
        $.ajax({
            url: url + "verifyCaptcha",
            type: "post",
            data: $(this).serialize(),
            dataType: "json",
            success: function (ret) {
                alert(ret.msg);
            }
        })
        return false;
    })

</script>
</body>
</html>